//
//  EventDetailViewController.m
//  IceBreaker
//
//  Created by Chiao Wolfire on 12-10-9.
//  Copyright (c) 2012年 NDS. All rights reserved.
//

#import "EventDetailViewController.h"
#import "CustomDetailCell.h"
#import "ApplyPopoverViewController.h"
#import "BlockPopoverViewController.h"
#import "ConcernPopoverViewController.h"
#import "ContactPopoverViewController.h"
#import "FPPopoverController.h"

@interface EventDetailViewController ()

@end

@implementation EventDetailViewController

// @synthesize detailTool;

#pragma mark - init
-(id) init {
    self = [super initWithNibName: nil bundle: nil];
    if (self) {
        self.title = @"活动详情";
    }
    return self;
}

-(id)initWithStyle:(UITableViewStyle)style {
    return [self init];
}

-(void)viewWillAppear: (BOOL)animated {
    [self.navigationController setToolbarHidden: NO];
    
    UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace 
                                                                              target: nil 
                                                                              action: nil];
    UIBarButtonItem *contactItem = [[UIBarButtonItem alloc] initWithImage: [UIImage imageNamed: @"communicate.png"] 
                                                                   style: UIBarButtonItemStylePlain 
                                                                  target: self 
                                                                  action: @selector(popContactWindow:)];
    [contactItem setTitle: @"对话"];
    UIBarButtonItem *applyItem = [[UIBarButtonItem alloc] initWithImage: [UIImage imageNamed: @"apply.png"] 
                                                                   style: UIBarButtonItemStylePlain 
                                                                  target: self 
                                                                  action: @selector(popApplyWindow:)];
    [applyItem setTitle: @"报名"];
    UIBarButtonItem *concernItem = [[UIBarButtonItem alloc] initWithImage: [UIImage imageNamed: @"concern.png"] 
                                                                 style: UIBarButtonItemStylePlain 
                                                                target: self 
                                                                action: @selector(popConcernWindow:)];
    [concernItem setTitle: @"关注"];
    UIBarButtonItem *blockItem = [[UIBarButtonItem alloc] initWithImage: [UIImage imageNamed: @"block.png"] 
                                                                 style: UIBarButtonItemStylePlain 
                                                                target: self 
                                                                action: @selector(popBlocktWindow:)];
    [blockItem setTitle: @"屏蔽"];

    [self setToolbarItems: [NSArray arrayWithObjects: flexItem, contactItem, flexItem, applyItem, flexItem, concernItem, flexItem, blockItem, flexItem, nil] 
                 animated: YES];
    [self.navigationController.toolbar setTintColor: [UIColor blackColor]];
    [contactItem release];
    [applyItem release];
    [concernItem release];
    [blockItem release];
    [flexItem release];
}

-(void)viewDidLoad
{
    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
 
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

-(void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

-(UITableViewCell *)tableView: (UITableView *)tableView 
         cellForRowAtIndexPath: (NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"CustomHomeDetailIdentifier";
    
    NSArray *eventImgs = [[NSArray alloc] initWithObjects: [UIImage imageNamed: @"detail1.png"], [UIImage imageNamed: @"detail2.png"], nil];
    NSArray *commentImgs = [[NSArray alloc] initWithObjects: [UIImage imageNamed: @"head.png"], [UIImage imageNamed: @"head.png"], [UIImage imageNamed: @"head.png"], [UIImage imageNamed: @"head.png"], nil];
    NSArray *comments = [[NSArray alloc] initWithObjects: @"我吐槽了你怎么地吧！", @"我还吐槽，你又怎么地吧！", @"我继续吐槽，你又能怎么地吧！", @"我依然吐槽，你咬我啊！", nil];

    CustomDetailCell *cell = [[[CustomDetailCell alloc] initWithStyle: UITableViewCellStyleDefault 
                                                      reuseIdentifier: CellIdentifier 
                                                              headImg: [UIImage imageNamed: @"head.png"] 
                                                                 name: @"Legend" 
                                                               gender: 1 
                                                                  age: 32 
                                                            eventType: @"美食" 
                                                             distance: 888.5 
                                                           eventTitle: @"不如一起 周末的午后，在中信广场来一场 2 vs 2的男女混双网球较量" 
                                                            eventImgs: eventImgs 
                                                          requirement: @"应该是一样的，关键是就是设置自动行数同时设置UILineBreakModeWordWrap（按文字折行）或者UILineBreakModeCharacterWrap（字符，好像是这样写）折行，主要依据你需要折行的内容，如果是一堆英文字母，则最好不用wordWrap" 
                                                         commentHeads: commentImgs 
                                                          commentTxts: comments] autorelease];

    cell.selectedBackgroundView = [[[UIView alloc] initWithFrame:cell.frame] autorelease];
    cell.selectedBackgroundView.backgroundColor = [UIColor clearColor];
    
    [eventImgs release];
    [commentImgs release];
    [comments release];
    
    return cell;
}

/*
// Override to support conditional editing of the table view.
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

#pragma mark - Table view delegate

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     [detailViewController release];
     */
}

-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    // return 1000;
    
    UITableViewCell *cell = [self tableView: tableView cellForRowAtIndexPath: indexPath];
    return cell.frame.size.height;
}

#pragma mark - instance methods
-(IBAction) popContactWindow:(id)sender {
    /*
    //the view controller you want to present as popover
    ContactPopoverViewController *controller = [[ContactPopoverViewController alloc] init];
    
    //our popover
    FPPopoverController *popover = [[FPPopoverController alloc] initWithViewController: controller];
    // popover.delegate = controller;
    popover.contentSize = CGSizeMake(150, 200);
    popover.tint = FPPopoverRedTint;
    popover.arrowDirection = FPPopoverArrowDirectionUp;

    //the popover will be presented from the tool bar
    [popover presentPopoverFromView: sender]; 
    //release
    [controller release];
    */
    
    
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Tips" 
                                                    message: @"对话" 
                                                   delegate: nil 
                                          cancelButtonTitle: @"OK" 
                                          otherButtonTitles: nil];
    [alert show];
    [alert release];
    
}

-(IBAction) popApplyWindow:(id)sender {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Tips" 
                                                    message: @"报名" 
                                                   delegate: nil 
                                          cancelButtonTitle: @"OK" 
                                          otherButtonTitles: nil];
    [alert show];
    [alert release];
}

-(IBAction) popConcernWindow:(id)sender {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Tips" 
                                                    message: @"关注" 
                                                   delegate: nil 
                                          cancelButtonTitle: @"OK" 
                                          otherButtonTitles: nil];
    [alert show];
    [alert release];
}

-(IBAction) popBlocktWindow:(id)sender {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Tips" 
                                                    message: @"屏蔽" 
                                                   delegate: nil 
                                          cancelButtonTitle: @"OK" 
                                          otherButtonTitles: nil];
    [alert show];
    [alert release];
}

// Know when a new popover is displayed
-(void)presentedNewPopoverController:(FPPopoverController *)newPopoverController 
          shouldDismissVisiblePopover:(FPPopoverController*)visiblePopoverController {
    
}

// Know when the popover is dismissed
-(void)popoverControllerDidDismissPopover:(FPPopoverController *)popoverController {
    
}

@end
